package com.laicunba.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.laicunba.dao.GenericQueryDao;
import com.laicunba.pojo.AccountDO;
import com.laicunba.service.AccountService;

@Service
public class AccountServiceImpl extends BaseServiceImpl implements AccountService {
	@Autowired
	private GenericQueryDao queryDao;

	@Override
	public List<AccountDO> listPlatformAccounts() {
		return queryDao.selectList("ACCOUNT.listPlatformAccounts", null);
	}

	@Override
	public BigDecimal totalBalance() {
		return queryDao.selectOne("ACCOUNT_BALANCE_SHEET.getTotalBalance", null);
	}

	@Override
	public boolean addBalance(String id, BigDecimal amt, BigDecimal oldBalance, long oldRowNum) {
		Map map = new HashMap();
		map.put("id", id);
		map.put("amt", amt);
		map.put("balance", oldBalance);
		map.put("oldRowNum", oldRowNum);
		return updateDao.update("ACCOUNT.addBalance", map) == 1;
	}

	@Override
	public boolean subtractBalance(String id, BigDecimal amt, BigDecimal oldBalance, long oldRowNum) {
		Map map = new HashMap();
		map.put("id", id);
		map.put("amt", amt);
		map.put("balance", oldBalance);
		map.put("oldRowNum", oldRowNum);
		return updateDao.update("ACCOUNT.subtractBalance", map) == 1;
	}
}
